//
//  DatePickerViewController.m
//  Pickers
//
//  Created by KaiKai on 11-7-18.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "DatePickerViewController.h"


@implementation DatePickerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [datePicker release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSDate *now = [[NSDate alloc] init];
    [datePicker setDate:now animated:YES];
    [now release];
}

- (void)viewDidUnload
{
    [datePicker release];
    datePicker = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)buttonPressed:(id)sender
{
    NSDate *selectedDate = [datePicker date];
    
    NSDateFormatter *dateformat = [[NSDateFormatter alloc] init];
    [dateformat setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateformat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
    NSString *dateInfo = [[dateformat stringFromDate:selectedDate] retain];
    
//    NSString *dateInfo = @"Abcdldk";

    NSString *info = [[NSString alloc] initWithFormat:@"You selected Date is %@", dateInfo];
    UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"Date and Time:" message:info delegate:nil cancelButtonTitle:@"Yes" otherButtonTitles:nil];
    
    [alterView show];
    [alterView release];
    
    [info release];
    [dateInfo release];
    [dateformat release];
}

@end
